package com.example.module_home

import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.lib_common.service.HelloService

@Route(path = "/home/HomeActivity")
class HomeActivity : AppCompatActivity() {
    //方案二：依赖注入
    @Autowired
    lateinit var helloService: HelloService
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_home)
        //方案二：依赖注入
        ARouter.getInstance().inject(this)
    }

    fun invokeUser(view: View) {
        //方案一：手动获取
//        val service:HelloService = ARouter.getInstance().build("/user/HelloService").navigation() as HelloService
//        val result = service.sayHello("张三")
//        Toast.makeText(this,result,Toast.LENGTH_SHORT).show()
        //方案二：依赖注入（推荐）
        val result = helloService.sayHello("张三")
        Toast.makeText(this,result,Toast.LENGTH_SHORT).show()
    }
}